<template>
    <div class="m_login">
        <mt-header title="登 录"></mt-header>
        <div class="m_logo">
            <img :src="$store.state.logo" alt="">
        </div>
        <div class="m_login-form">
            <mt-field label="邮箱" placeholder="请输入用户名" v-model="formLogin.mail"></mt-field>
            <mt-field label="密码" placeholder="请输入密码" type="password" v-model="formLogin.pwd"></mt-field>
        </div>
        <mt-cell class="m_forget_password">
            <router-link to="/m/forget">
                <el-button type="text">忘记密码</el-button>
            </router-link>
        </mt-cell>
        <mt-button type="primary" size="large" @click.native="onSubmit">登录</mt-button>
        <p class="m_go-login">
            <router-link to="/m/register">
                <el-button type="text">还没有账号，<b>去注册</b></el-button>
            </router-link>
        </p>

    </div>
</template>

<script>

    import {mapMutations} from 'vuex'


    export default {
        name: "Login",
        data() {
            return {
                formLogin: {
                    mail: "",
                    pwd: ""
                }
            }
        },
        methods: {
            ...mapMutations(['changeLogin']),
            onSubmit() {
                if (this.formLogin.mail === '' || this.formLogin.pwd === '') {
                    alert('账号或密码不能为空');
                    return false;
                } else {
                    this.requestAxios.requestWeb(null, "/login.do", {
                        mail: this.formLogin.mail,
                        pwd: this.$md5(this.formLogin.pwd),
                    }, (response) => {
                        this.changeLogin({sid: response.data.sid, user: response.data.user});
                        this.$cookies.set('sid', response.data.sid, '7d');
                        this.$cookies.set('user', response.data.user, '7d');
                        this.$router.push("/m/home")
                    });
                }
            },

        }

    }
</script>

<style scoped>
    @import '../../../assets/css/m/style.css';
</style>
